# Maintainer: Rafał Brzegowy <rafal.brzegowy@yahoo.com>

_realname=tfel
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=5.0.1
pkgrel=1
pkgdesc='MFront: a code generation tool dedicated to material knowledge (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
provides=("${MINGW_PACKAGE_PREFIX}-mfront")
depends=("${MINGW_PACKAGE_PREFIX}-gnuplot"
         $([[ ${MINGW_PACKAGE_PREFIX} == *-clang-* ]] || echo "${MINGW_PACKAGE_PREFIX}-gcc-libgfortran") )
makedepends=("unzip"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-cc"
             $([[ ${MINGW_PACKAGE_PREFIX} == *-clang-* ]] || echo "${MINGW_PACKAGE_PREFIX}-gcc-fortran") )
license=('spdx:GPL-3.0-or-later')
url='https://tfel.sourceforge.io/'
source=(https://github.com/thelfer/${_realname}/archive/TFEL-${pkgver}.zip)
sha256sums=('bf8ce82ab00d8472f9c7bd2640efc419e400b08c6ef04b6464af799c8216f589')
noextract=("TFEL-${pkgver}.zip") # bsdtar could not unpack this archive

prepare() {
  unzip -oq TFEL-${pkgver}.zip -d "${srcdir}"
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  declare -a extra_conf
  case ${MSYSTEM} in
    CLANG*)
      extra_conf+=("-Denable-fortran=OFF");;
    *)
      extra_conf+=("-Denable-fortran=ON");;
  esac

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DCMAKE_BUILD_TYPE=Release \
      -Denable-python=OFF \
      -Denable-python-bindings=OFF \
      -Denable-aster=ON \
      -Denable-abaqus=ON \
      -Denable-ansys=ON \
      -Denable-europlexus=ON \
      -Denable-zmat=ON \
      -Denable-cyrano=ON \
      -Denable-calculix=ON \
      -Denable-comsol=ON \
      -Denable-diana-fea=ON \
      -Denable-lsdyna=ON \
      -Denable-cxx-17=ON \
      -Denable-portable-build=ON \
      -Denable-reference-doc=OFF \
      ${extra_conf} \
      ../${_realname}-TFEL-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  DESTDIR="${pkgdir}" cmake --build . --target install
  install -Dm644 "${srcdir}"/${_realname}-TFEL-${pkgver}/LICENCE-GNU-GPL "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}

# vim: ts=2 sw=2 et:
